package nowcoder.day_48.day5;

import java.util.Scanner;

/**
 * DD1 连续最大和
 */
public class Num2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int []data =new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();
        }
        int res = data[0];
        int[]dp = new int[n];
        dp[0] = data[0];
        //dp[i]表示以i下标结尾的最大连续子数组的和
        for (int i = 1; i < n; i++) {
            dp[i] = Math.max(dp[i - 1] + data[i] , data[i]);
            res = Math.max(res , dp[i]);
        }
        System.out.println(res);


    }
}
